﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using nplJobsCommon.JobSeeker;
using System.Data.SqlClient;
using nplJobsCommon;
using nplJobsCommon.Employeer;

namespace nplJobsDAL.Insert
{
    /// <summary>
    /// This class is used to insert job seeker's data
    /// </summary>
    public class InsertEmployeer : DataAccessBase
    {
        public Int64 lastEmployeerID = -1;
        public string checkUnique;

        public Employeer Employeer { get; set; }

        public InsertEmployeer()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertEmployeer.ToString();
        }

        public void Insert()
        {
            InsertEmployeerDataParameters insertEmployeerDataParameters = new InsertEmployeerDataParameters(this.Employeer);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = insertEmployeerDataParameters.Parameters;
            //object lastEmployeerID = dbHelper.RunScalar();

            //if (lastEmployeerID != null)
            //{
            //    this.lastEmployeerID = Int64.Parse(lastEmployeerID.ToString());
            //}
             dbHelper.RunScalar();

        }
    }

    #region SQL parameters for employee insert data
    public class InsertEmployeerDataParameters
    {
        public int CkeckUnique;
        private SqlParameter[] _parameters;

        public InsertEmployeerDataParameters(Employeer employeer)
        {
            this.Employeer = employeer;
            Build();
        }

        #region spAddContact parameters
        /*
         
         */
        #endregion

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                   new SqlParameter("@EmployeerID", Employeer.EmployeerID),
                    new SqlParameter("@CompanyName", Employeer.CompanyName),
                    new SqlParameter("@Password", Employeer.Password),
                    new SqlParameter("@EmployeerTypeID", Employeer.EmployeerTypeID),
                    new SqlParameter("@IndustryTypeID", Employeer.IndustryTypeID),
                    new SqlParameter("@CompanyDescription", Employeer.CompanyDescription),
                    new SqlParameter("@Country", Employeer.Country),
                    new SqlParameter("@City", Employeer.City),
                    new SqlParameter("@CityName", Employeer.CityName),
                    new SqlParameter("@LocationID", Employeer.LocationID),
                    new SqlParameter("@Address", Employeer.Address),
                    new SqlParameter("@ContactPersonID", Employeer.ContactPersonID),
                    new SqlParameter("@CompanyImage", Employeer.EmployeerImagePath),
                    new SqlParameter("@EmployeeRangeID", Employeer.EmployeeRangeID),
                    new SqlParameter("@Phone", Employeer.Phone),
                    new SqlParameter("@MobilePhone", Employeer.MobilePhone),
                    new SqlParameter("@Fax", Employeer.Fax),
                    new SqlParameter("@HomePageUrl", Employeer.HomePageUrl),

                    new SqlParameter("@FirstName", Employeer.EmployeerContactPerson.FirstName),
                    new SqlParameter("@LastName", Employeer.EmployeerContactPerson.LastName),
                    new SqlParameter("@TitleID", Employeer.EmployeerContactPerson.TitleID),
                    new SqlParameter("@DesignationID", Employeer.EmployeerContactPerson.DesignationID),
                    new SqlParameter("@ContactNumber", Employeer.EmployeerContactPerson.ContactNumber ),
                    new SqlParameter("@Email",Employeer.Email),
                    new SqlParameter("@UserType", Employeer.UserType),

                    //,new SqlParameter("@LastEmployeerID",  LastEmployeerID){ Direction= System.Data.ParameterDirection.ReturnValue},
                };

            Parameters = parameters;
        }

        public Employeer Employeer { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
    }
    #endregion
}

